package org.dromara.bykt.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.bykt.domain.BYKTCourseCategory;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bykt.domain.vo.BYKTCourseCategoryVo;
import org.dromara.bykt.domain.bo.BYKTCourseCategoryBo;
import org.dromara.bykt.service.IBYKTCourseCategoryService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 课程分类
 *
 * @author Hou
 * @date 2025-06-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/bykt/category")
public class BYKTCourseCategoryController extends BaseController {

    private final IBYKTCourseCategoryService courseCategoryService;

    /**
     * 查询课程分类列表
     */
    @GetMapping("/list")
    public TableDataInfo<BYKTCourseCategoryVo> list(BYKTCourseCategoryBo bo, PageQuery pageQuery) {
        return courseCategoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出课程分类列表
     */
    @Log(title = "课程分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BYKTCourseCategoryBo bo, HttpServletResponse response) {
        List<BYKTCourseCategoryVo> list = courseCategoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "课程分类", BYKTCourseCategoryVo.class, response);
    }

    /**
     * 获取课程分类详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<BYKTCourseCategoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(courseCategoryService.queryById(id));
    }

    /**
     * 新增课程分类
     */
    @Log(title = "课程分类", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@RequestBody BYKTCourseCategoryBo bo) {
        return toAjax(courseCategoryService.insertByBo(bo));
    }

    /**
     * 修改课程分类
     */
    @Log(title = "课程分类", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@RequestBody BYKTCourseCategoryBo bo) {
        return toAjax(courseCategoryService.updateByBo(bo));
    }

    /**
     * 删除课程分类
     *
     * @param ids 主键串
     */
    @Log(title = "课程分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(courseCategoryService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 课程分类列表
     * @return
     */
    @GetMapping("/queryCourseCategory")
    public R<List<BYKTCourseCategoryVo>> queryCourseCategory() {
        return R.ok(courseCategoryService.queryCourseCategory());
    }
}
